package com.shijianchen.utils;

import java.lang.reflect.Field;
import java.util.HashMap;

/**
 * 反射工具类
 */
public class RevokeUtils {
    public static <T,Object> HashMap<String, Object> revokeBecomeMap(T instance) throws IllegalAccessException {
        Class<?> aClass = instance.getClass();
        Field[] fields = aClass.getDeclaredFields();
        HashMap<String, Object> map = new HashMap<>();
        for (Field field : fields) {
            field.setAccessible(true);
            String name = field.getName();
            Object value = (Object) field.get(instance);
            if (value instanceof String) {
                if (!((String) value).isEmpty()) {
                    map.put(name, value);
                }
            } else {
                if (value != null) {
                    map.put(name, value);
                }
            }
        }
        return map;
    }
}
